Edit your first key

After setting up our environment, we’re going to create our first key. Keys in tweek are the most basic building blocks and they represent a container for dynamic value that affect feature behaviors. Our first key, will be a key that is responsible for the color of a “sign up” button.

  • Open http://localhost:8081/login in browser.
  • Login
    • User Basic auth (user: admin-app, password: 8v/iUG0vTH4BtVgkSn3Tng==)
    • Can also use OIDC mock server login button for testing OIDC (user: User, password: pwd)
  • Go to keys page.
  • Click on “Add Key”
  • Type my_app/sign_button/color
  • Set value type to String
  • Add default value “red”
  • Save changes
  • Click on “Add Rule”
  • Set Property to Country (user) and set “=” and “Canada” in the other fields
  • In Rule value set the value “blue”
  • Click “Save changes”

More on keys and paths

Querying Tweek

Use curl/postman/chrome to fire GET Request:

  • http://localhost:8081/api/v2/values/my_app/sign_button/color -> expected to be “red”
  • http://localhost:8081/api/v2/values/my_app/sign_button/color?user.Country=canada -> expected to be “blue”
  • http://localhost:8081/api/v2/values/my_app/sign_button/_?user.Country=canada -> expected to be {“color”:”blue”}

Using the rest api, an application can query Tweek for getting the right set of values for each specific user. More on Tweek Rest api.

Adding context data

Tweek provide UI and rest api for editing context.

  • Go to context
  • Set Identity Type to User
  • Set User id to John
  • Click enter
  • Set value “Canada” for property Country

After that, we can query Tweek API with:

  • http://localhost:8081/api/v2/values/my_app/sign_button/color?user=john -> expected to be “blue”

You can also use the api for updating Tweek context:

  • curl -X POST http://localhost:8081/api/v2/context/user/john
    -H ‘content-type: application/json’
    -H ‘x-client-id: admin-app’
    -H ‘x-client-secret: 8v/iUG0vTH4BtVgkSn3Tng==’
    -d ‘{ “country”: “Canada” }’

More on Context.

Gradual Feature Release

Create new key in the editor “my_app/sign_button/is_enabled” with value type “boolean” and default value False.
Add new rule, remove all conditions, set the the rule value to gradual release with 50%. Try querying configuration with different users and You’ll have different results.

  • http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=barny
  • http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=robin
  • http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=ted
  • http://localhost:8081/api/v2/values/my_app/sign_button/is_enabled?user=lily
  • etc…

More on how multi-variant keys work in Tweek. (link)